# Build recipe for wicd.
#
# Copyright (C) 2019 Kevin "The Nuclear" Bloom, <nuclearkev@dragora.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=wicd
version=1.7.4
release=4

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/devel"

tarname=${program}-${version}.tar.gz

# Remote source(s)
# fetch=https://launchpad.net/wicd/1.7/1.7.4/+download/$tarname

description="
wicd - a wired/wireless network manager
"

homepage=http://wicd.sourceforge.net/
license="GPLv2+"

# Source documentation
docs="AUTHORS CHANGES LICENSE MANIFEST* NEWS PKG-INFO README"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # trick wicd into thinking we are slackware ;)
    echo "Dragora 3.0.0-APLHA" > /etc/slackware-version

    patch -p0 < "${worktree}/patches/wicd/38-fix_build_failure_when_LANG_empty.patch"

    python setup.py configure \
    --lib=/usr/lib${libSuffix} \
    --sbin=/usr/bin \
    --no-install-init \
    --verbose \
    --no-install-gnome-shell-extensions

    python setup.py build
    python setup.py compile_translations

    python setup.py install \
     --root="$destdir"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"
}
